// 108.将有序数组转为二叉搜索树
package LeetcodeHot100;


public class Solution108 {
    public TreeNode sortedArrayToBST(int[] nums) {
        TreeNode result = binary(nums, 0, nums.length - 1);
        return result;
    }

    public TreeNode binary(int[] nums, int left, int right) {
        if (left > right)
            return null;
        else if (left == right) {
            return new TreeNode(nums[left]);
        } else {
            int mid = (left + right) / 2;
            TreeNode root = new TreeNode(nums[mid]);
            root.left = binary(nums, left, mid - 1);
            root.right = binary(nums, mid + 1, right);
            return root;
        }
    }
}

